/***********************************************************************
 * Module:  AnswerItem.java
 * Author:  DAC
 * Purpose: Defines the Class AnswerItem
 ***********************************************************************/
package com.group1.model;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

/** @pdOid 4a6870f1-b82e-492d-8af3-0abadd6800d7 */
public class AnswerItem {
   /** @pdOid da5366ff-6add-4652-ade6-b9329e584fb1 */
   protected void finalize() {
      // TODO: implement
   }
   
   /** @pdOid 5837d95a-9ad2-4e5f-b86e-1050e28edc94 */
   public Integer ansiId;
   /** @pdOid 664528d7-ab30-41ea-b399-86ab35fa1fd1 */
   public java.lang.String ansiDesc;
   /** For Fill-in-blank question
    * 
    * @pdOid ef9bb84f-38b9-4f6b-b13c-efaa5530f866 */
   public java.lang.String ansiValue;
   /** @pdOid 58a20bf8-d93b-4e15-aca1-70b9521755d5 */
   public boolean ansiIsSolution;
   
   /** @pdRoleInfo migr=no name=QuestionImage assc=picturesForAnswerItems coll=java.util.Collection impl=java.util.HashSet mult=0..* */
   public java.util.Collection<QuestionImage> questionImage;
   /** @pdRoleInfo migr=no name=Question assc=answerItemsOfQuestions mult=0..1 side=A */
   public Question question;
   
   /** @param answID 
    * @param answDesc 
    * @param answValue 
    * @param answSolution 
    * @param questID
    * @pdOid 8c1b0bf8-56a6-4f0b-9373-4d5eacafced8 */
   public AnswerItem(Integer answID, String answDesc, String answValue, boolean answSolution, Integer questID) {
	   this.ansiId = answID;
	   this.ansiDesc = answDesc;
	   this.ansiIsSolution = answSolution;
	   this.question.questionId = questID;
   }
   
   
   /** @param questID 
    * @param session
    * @pdOid ac47dd9f-a235-480f-bd89-e6d247829895 */
   public static List<AnswerItem> getAllAnswByQuestion(Integer questID, Session session) {
      // TODO: implement
	   Query query = session.createQuery("from AnswerItem where QUESTION_ID = '" + questID+"'");
	   List<AnswerItem> list = query.list();
      return list;
   }
   
   /** @param answId 
    * @param session
    * @pdOid b10eaeda-8785-47e9-bfb1-09ab30a995be */
   public static AnswerItem getAnswById(Integer answId, Session session) {
      // TODO: implement
      return (AnswerItem) session.get(AnswerItem.class, answId);
   }
   
   
   /** @pdOid 5e37cdfa-a317-4e07-bc47-bb1a254b9ce0 */
   public Integer getAnsiId() {
      return ansiId;
   }
   
   /** @param newAnsiId
    * @pdOid 29c994f0-53d1-4de5-aba4-c50d4a6298d6 */
   public void setAnsiId(Integer newAnsiId) {
      ansiId = newAnsiId;
   }
   
   /** @pdOid fa26a73f-5221-4c81-a72f-3e1772804a3f */
   public java.lang.String getAnsiDesc() {
      return ansiDesc;
   }
   
   /** @param newAnsiDesc
    * @pdOid d67597fb-da28-4eaf-a82a-39c336b67ada */
   public void setAnsiDesc(java.lang.String newAnsiDesc) {
      ansiDesc = newAnsiDesc;
   }
   
   /** @pdOid 04eeded5-a706-4ce1-9cd5-65e2b917f768 */
   public java.lang.String getAnsiValue() {
      return ansiValue;
   }
   
   /** @param newAnsiValue
    * @pdOid fd76e387-5b4d-45d6-a249-415cf5c69ded */
   public void setAnsiValue(java.lang.String newAnsiValue) {
      ansiValue = newAnsiValue;
   }
   
   /** @pdOid c5b685b0-68c2-4514-90fb-48ca31455010 */
   public boolean getAnsiIsSolution() {
      return ansiIsSolution;
   }
   
   /** @param newAnsiIsSolution
    * @pdOid 04f8a0c1-fd07-4a61-bbcc-300856325de1 */
   public void setAnsiIsSolution(boolean newAnsiIsSolution) {
      ansiIsSolution = newAnsiIsSolution;
   }
   
   /** @pdOid 54916ff4-fb6a-41d4-b6d7-189ae4e844e8 */
   public AnswerItem() {
      // TODO: implement
   }
   
   
   /** @pdGenerated default getter */
   public java.util.Collection<QuestionImage> getQuestionImage() {
      if (questionImage == null)
         questionImage = new java.util.HashSet<QuestionImage>();
      return questionImage;
   }
   
   /** @pdGenerated default iterator getter */
   public java.util.Iterator getIteratorQuestionImage() {
      if (questionImage == null)
         questionImage = new java.util.HashSet<QuestionImage>();
      return questionImage.iterator();
   }
   
   /** @pdGenerated default setter
     * @param newQuestionImage */
   public void setQuestionImage(java.util.Collection<QuestionImage> newQuestionImage) {
      removeAllQuestionImage();
      for (java.util.Iterator iter = newQuestionImage.iterator(); iter.hasNext();)
         addQuestionImage((QuestionImage)iter.next());
   }
   
   /** @pdGenerated default add
     * @param newQuestionImage */
   public void addQuestionImage(QuestionImage newQuestionImage) {
      if (newQuestionImage == null)
         return;
      if (this.questionImage == null)
         this.questionImage = new java.util.HashSet<QuestionImage>();
      if (!this.questionImage.contains(newQuestionImage))
      {
         this.questionImage.add(newQuestionImage);
         newQuestionImage.setAnswerItem(this);      
      }
   }
   
   /** @pdGenerated default remove
     * @param oldQuestionImage */
   public void removeQuestionImage(QuestionImage oldQuestionImage) {
      if (oldQuestionImage == null)
         return;
      if (this.questionImage != null)
         if (this.questionImage.contains(oldQuestionImage))
         {
            this.questionImage.remove(oldQuestionImage);
            oldQuestionImage.setAnswerItem((AnswerItem)null);
         }
   }
   
   /** @pdGenerated default removeAll */
   public void removeAllQuestionImage() {
      if (questionImage != null)
      {
         QuestionImage oldQuestionImage;
         for (java.util.Iterator iter = getIteratorQuestionImage(); iter.hasNext();)
         {
            oldQuestionImage = (QuestionImage)iter.next();
            iter.remove();
            oldQuestionImage.setAnswerItem((AnswerItem)null);
         }
      }
   }
   /** @pdGenerated default parent getter */
   public Question getQuestion() {
      return question;
   }
   
   /** @pdGenerated default parent setter
     * @param newQuestion */
   public void setQuestion(Question newQuestion) {
      if (this.question == null || !this.question.equals(newQuestion))
      {
         if (this.question != null)
         {
            Question oldQuestion = this.question;
            this.question = null;
            oldQuestion.removeAnswerItem(this);
         }
         if (newQuestion != null)
         {
            this.question = newQuestion;
            this.question.addAnswerItem(this);
         }
      }
   }

}